class Solution {
public:
    int maximalRectangle(vector<vector<char>>& matrix)
    {
        if (matrix.size() == 0)
        {
            return 0;
        }
        vector<vector<int>> left(matrix.size(), vector<int>(matrix.front().size(), 0));

        for (int cntRow = 0; cntRow < matrix.size(); cntRow++)
        {
            for (int cntCol = 0; cntCol < matrix.front().size(); cntCol++)
            {
                if (matrix[cntRow][cntCol] == '1')
                {
                    left[cntRow][cntCol] = cntCol == 0 ? 1 : (left[cntRow][cntCol - 1] + 1);      // 位置 left[cntRow][cntCol] 左侧
                }

            }
        }

        int ret = 0;
        for (int cntRow = 0; cntRow < matrix.size(); cntRow++)
        {
            for (int cntCol = 0; cntCol < matrix.front().size(); cntCol++)
            {
                if (left[cntRow][cntCol] == 0)
                {
                    continue;
                }
                int width = left[cntRow][cntCol], area = width;
                for (int backCntRow = cntRow - 1; backCntRow >= 0; backCntRow--)
                {
                    width = min(width, left[backCntRow][cntCol]);
                    area = max(area, width * (cntRow - backCntRow + 1));
                }
                ret = max(ret, area);

            }
        }
        return ret;
    }
};